<?php
/**
 * Login_Model_Activateaccount
 * activate account model
 *
 * @author Adrian Stolarski
 */
class Login_Model_Activateaccount implements Login_Model_Mainable, 
        Login_Model_Redirectable, Login_Model_Setable, Login_Model_Getable, 
        Login_Model_Checkable {
    
    /**
     *
     * @var type $redirect_action
     * redirect action handler
     */
    public $redirect_action;
    /**
     *
     * @var type $check_activate_data
     * check activate data handler
     */
    public $check_activate_data;
    /**
     *
     * @var type $check_user_object
     * user object data handler
     */
    public $check_user_object;
    /**
     *
     * @var type $set_data
     * set data handler
     */
    public $set_data;
    
    /**
     * chack_data()
     * check post data
     * 
     * @param array $variables
     */
    public function check_data(array $variables = null) {
        //var_dump($variables);
        //die();
        if(!isset($variables['csrf_token']) 
                || !isset($variables['user_email']) 
                || !isset($variables['user_password']) 
                || ($variables['csrf_token'] != $_SESSION['csrf_token'])){
            $this->redirect_action($variables);
        }
    }
    
    /**
     * get_user_data()
     * get current user_data
     * @param type $value
     * @param type $key
     * @return type $userdata
     */
    public function get_user_data($value, $key = null) {
        $variables['user_email'] = $value;
        $this->check_activate_data = new Login_Data_Checkactivatedata;
        $userdata = $this->check_activate_data->main($variables);
        if(!is_null($userdata) && ($userdata['id'] != null)){
            return $userdata;
        }
        else {
            $this->redirect_action($userdata);
        }
    }

    public function main(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->check_data($variables);
        $value = $variables['user_email'];
        $user_data = $this->get_user_data($value);
        $this->set_data($user_data);
    }
    
    /**
     * redirect_action()
     * activate account form redirect
     * 
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Login_Data_Activateacountredirect;
        $this->redirect_action->main($variables);
    }

    public function set_data(array $variables = null) {
        $this->check_user_object = new Login_Model_Checkuserobject;
        $this->check_user_object->main($variables);
    }

}
